package com.example.day2.exercise;

import java.util.Objects;

/**
 * 写出等价的 lambda 表达式
 */
public class Exercise2 {
    public static void main(String[] args) {
        // Math::random () -> Math.random()
        // Math::sqrt (a) -> Math.sqrt(a)
        // Student::getName stu -> stu.getName()
        // Student::setName (stu,name) -> stu.setName(name)
        // Student::hashCode (stu) -> stu.hashCode()
        // Student::equals (stu1,stu2) -> stu1.equals(stu2)

        // 假设已有对象 Student stu = new Student("张三");
        // stu::getName () -> stu.getName()
        // stu::setName (name) -> stu.setName(name)
        // Student::new (name) -> new Student(name)
    }

    static class Student {
        private String name;

        public Student(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Student student = (Student) o;
            return Objects.equals(name, student.name);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name);
        }
    }
}
